package com.ciaojian.core.service;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ciaojian.core.enums.business.WorkerApplyStatusEnum;
import com.ciaojian.core.mapper.SchedulingMapper;
import com.ciaojian.core.model.Scheduling;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 排班表 服务类
 * </p>
 *
 * @author Atlakyn
 * @since 2021-03-25
 */
public abstract class SchedulingService<M extends BaseMapper<T>, T> extends ServiceImpl<SchedulingMapper, Scheduling> {


    /**
     * 获取发型师今日排班
     *
     * @param workerId 发型师 ID
     * @return 今日排班
     */
    public Scheduling getWorkerScheduledToday(Integer workerId) {
        LambdaQueryWrapper<Scheduling> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Scheduling::getWorkerId, workerId)
                .eq(Scheduling::getStatus, WorkerApplyStatusEnum.PASS)
                .eq(Scheduling::getDate, DateUtil.today());
        return new Scheduling().selectOne(lambdaQueryWrapper);
    }

    /**
     * 查询发型师指定时间段内的排班
     *
     * @param workerId 发型师ID
     * @param begin    开始时间
     * @param end      结束时间
     * @return 排班列表
     */
    public List<Scheduling> listByWorkerIdAndBetweenDate(Integer workerId, Date begin, Date end) {
        return lambdaQuery()
                .between(Scheduling::getDate, begin, end)
                .eq(Scheduling::getWorkerId, workerId)
                .list();
    }

}
